package com.zmkm.util;

import java.util.regex.Pattern;

public class StringOrInt {
	public static Integer toInt(String a) {
		if (a.indexOf(".") != -1) {
			String a_begin = a.substring(0, a.indexOf("."));
			String a_end = a.substring(a.indexOf(".") + 1);
			String b;
			if (a_end.length() >= 2) {
				b = (new StringBuilder(String.valueOf(a_begin))).append(a_end.substring(0, 2)).toString();
			} else {
				b = (new StringBuilder(String.valueOf(a_begin))).append(a_end).append("0").toString();
			}
			return Integer.valueOf(Integer.parseInt(b));
		}
		return Integer.valueOf(Integer.parseInt(a + "00"));
	}

	public static String optimize(String nmb) {
		return toString(toInt(nmb));
	}

	public static boolean stringVerify(String nmb) {
		Pattern pattern = Pattern.compile("^[-\\+]?[\\d]*$");
		return pattern.matcher(nmb).matches();
	}

	public static String toString(Integer p) {
		String pd = Integer.toString(p.intValue());
		String pd_begin = pd.substring(0, pd.length() - 2);
		String pd_end = pd.substring(pd.length() - 2);
		pd = (new StringBuilder(String.valueOf(pd_begin))).append(".").append(pd_end).toString();
		return pd;
	}
}
